package com.muyan.countdownlatch;

import java.util.concurrent.CountDownLatch;

class Timer implements Runnable {
	CountDownLatch timerController;

	public Timer(int numOfAthlete) {
		this.timerController = new CountDownLatch(numOfAthlete);
	}

	public void recordResult(String athleteName) {
		System.out.println(athleteName + " has arrived");
		timerController.countDown();
		System.out.println("There are " + timerController.getCount() + " athletes did not reach the end");
	}

	public void run() {
		try {
			System.out.println("Start...");
			timerController.await();
			System.out.println("All the athletes have arrived");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}